﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;
using System.Data;
using System.Configuration;

namespace NoteSystem.utils
{
    public class DbHelper
    {
        /// <summary>
        /// 查询数据库，返回数据结果
        /// </summary>
        /// <returns></returns>
        public static DataSet Query(string sql)
        {
            MySqlConnection cn = new MySqlConnection(ConfigurationManager.ConnectionStrings["notesystem"].ConnectionString);
            MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter(sql, cn);
            DataSet ds = new DataSet();
            mySqlDataAdapter.Fill(ds);
            return ds;
        }
        /// <summary>
        /// 传进来一个SQL操作语句，返回一个受影响行数
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static int ExecuteSql(string sql)
        {
            MySqlConnection connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["notesystem"].ConnectionString);
            MySqlCommand cmd = new MySqlCommand(sql, connection);
            connection.Open();
            int flag = cmd.ExecuteNonQuery();
            connection.Close();
            return flag;
        }

    }
}